package pokerclient.view.panels;

import javax.swing.GroupLayout;
import javax.swing.JComponent;

import org.jdesktop.application.Application;

import common.Card;

import javax.swing.JLabel;
import javax.swing.LayoutStyle;

/**
 * This code was edited or generated using CloudGarden's Jigloo SWT/Swing GUI
 * Builder, which is free for non-commercial use. If Jigloo is being used
 * commercially (ie, by a corporation, company or business for any purpose
 * whatever) then you should purchase a license for each developer using Jigloo.
 * Please visit www.cloudgarden.com for details. Use of Jigloo implies
 * acceptance of these licensing terms. A COMMERCIAL LICENSE HAS NOT BEEN
 * PURCHASED FOR THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED LEGALLY FOR
 * ANY CORPORATE OR COMMERCIAL PURPOSE.
 */
public class DealerPanel extends javax.swing.JPanel {
	private static final long serialVersionUID = -5526161235827710923L;
	private JLabel dealerCard1Label;
	private JLabel dealerCard3Label;
	private JLabel dealerCard4Label;
	private JLabel dealerCard5Label;
	private JLabel dealerCard2Label;

	private JLabel[] dealerCardLabels;

	/**
	 * Auto-generated main method to display this JPanel inside a new JFrame.
	 */

	public DealerPanel() {
		super();
		initGUI();

		// Make our life easier later on:
		dealerCardLabels = new JLabel[5];
		dealerCardLabels[0] = dealerCard1Label;
		dealerCardLabels[1] = dealerCard2Label;
		dealerCardLabels[2] = dealerCard3Label;
		dealerCardLabels[3] = dealerCard4Label;
		dealerCardLabels[4] = dealerCard5Label;
		Card emptyCard = new Card();
		for (int i = 0; i < 5; i++) {
			dealerCardLabels[i].setIcon(emptyCard.getIcon());
		}
	}

	private void initGUI() {
		try {
			GroupLayout thisLayout = new GroupLayout((JComponent) this);
			this.setLayout(thisLayout);
			this.setPreferredSize(new java.awt.Dimension(525, 146));
			{
				dealerCard1Label = new JLabel();
				dealerCard1Label.setName("dealerCard1Label");
				dealerCard1Label.setSize(71, 96);
			}
			{
				dealerCard2Label = new JLabel();
				dealerCard2Label.setName("dealerCard2Label");
				dealerCard2Label.setSize(71, 96);
			}
			{
				dealerCard3Label = new JLabel();
				dealerCard3Label.setName("dealerCard3Label");
				dealerCard3Label.setSize(71, 96);
			}
			{
				dealerCard4Label = new JLabel();
				dealerCard4Label.setName("dealerCard4Label");
				dealerCard4Label.setSize(71, 96);
			}
			{
				dealerCard5Label = new JLabel();
				dealerCard5Label.setName("dealerCard5Label");
				dealerCard5Label.setSize(71, 96);
			}
			thisLayout.setVerticalGroup(thisLayout.createSequentialGroup()
				.addContainerGap(25, 25)
				.addGroup(thisLayout.createParallelGroup(GroupLayout.Alignment.BASELINE)
				    .addComponent(dealerCard2Label, GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE, 96, GroupLayout.PREFERRED_SIZE)
				    .addComponent(dealerCard1Label, GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE, 96, GroupLayout.PREFERRED_SIZE)
				    .addComponent(dealerCard3Label, GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE, 96, GroupLayout.PREFERRED_SIZE)
				    .addComponent(dealerCard4Label, GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE, 96, GroupLayout.PREFERRED_SIZE)
				    .addComponent(dealerCard5Label, GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE, 96, GroupLayout.PREFERRED_SIZE))
				.addContainerGap(25, 25));
			thisLayout.setHorizontalGroup(thisLayout.createSequentialGroup()
				.addContainerGap()
				.addComponent(dealerCard1Label, GroupLayout.PREFERRED_SIZE, 71, GroupLayout.PREFERRED_SIZE)
				.addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED)
				.addComponent(dealerCard2Label, GroupLayout.PREFERRED_SIZE, 71, GroupLayout.PREFERRED_SIZE)
				.addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED)
				.addComponent(dealerCard3Label, GroupLayout.PREFERRED_SIZE, 71, GroupLayout.PREFERRED_SIZE)
				.addGap(48)
				.addComponent(dealerCard4Label, GroupLayout.PREFERRED_SIZE, 71, GroupLayout.PREFERRED_SIZE)
				.addGap(31)
				.addComponent(dealerCard5Label, GroupLayout.PREFERRED_SIZE, 71, GroupLayout.PREFERRED_SIZE)
				.addContainerGap(55, Short.MAX_VALUE));
			Application.getInstance().getContext().getResourceMap(getClass())
					.injectComponents(this);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public void showFlop(Card[] communityCards) {
		if (!(communityCards == null)) {
			for (int i = 0; i < 5; i++) {
				Card ourCard = communityCards[i];
				if (ourCard != null) {
					dealerCardLabels[i].setText("");
					dealerCardLabels[i].setIcon(ourCard.getIcon());
				} else {
					dealerCardLabels[i].setText("");
					dealerCardLabels[i].setIcon(new Card().getIcon());
				}
			}
		}
	}
}
